//
//  NSObject+WLVC.m
//  xiacai_ios_v6
//
//  Created by 王亮 on 2018/5/4.
//  Copyright © 2018年 王振标. All rights reserved.
//

#import "NSObject+WLVC.h"

@implementation NSObject (WLVC)
- (UIViewController *)topViewController_wl {
    UIViewController *resultVC;
    resultVC = [self _topViewController:[[UIApplication sharedApplication].keyWindow rootViewController]];
    while (resultVC.presentedViewController) {
        resultVC = [self _topViewController:resultVC.presentedViewController];
    }
    return resultVC;
}
- (UIViewController *)_topViewController:(UIViewController *)vc {
    if ([vc isKindOfClass:[UINavigationController class]]) {
        return [self _topViewController:[(UINavigationController *)vc topViewController]];
    } else if ([vc isKindOfClass:[UITabBarController class]]) {
        return [self _topViewController:[(UITabBarController *)vc selectedViewController]];
    } else {
        return vc;
    }
    return nil;
}
@end
